//
// Created by postgres on 4/19/17.
//
#include "../include/03StackQueue/stack.h"
Status InitStackLink(StackLink *head){
    *head=(StackLink)palloc(sizeof(StackNodeLink));
    if(*head==NULL)return ERROR;
    else{
        (*head)->next=NULL;
        return OK;
    }
}

Status StackLinkEmpty(StackLink head)
/*判断链栈是否为空，就是通过判断头结点的指针域是否为空*/
{
    if(head->next==NULL)				/*判断链栈头结点的指针域是否为空*/
        return TRUE;					/*当链栈为空时，返回1；否则返回0*/
    else
        return FALSE;
}
Status PushStackLink(StackLink *head,ElemType e){
    StackLink p;
    p=(StackLink)palloc(sizeof(StackNodeLink));
    if(p==NULL)return ERROR;
    p->data=e;
    p->next=(*head)->next;
    (*head)->next=p;
    return OK;

}
Status PopStackLink(StackLink *head,ElemType *e){
    if(StackLinkEmpty(*head))
        return ERROR;
    StackLink p;
    p=(*head)->next;
    *e=p->data;
    (*head)->next=p->next;
    pfree(p);
    return OK;

}
Status GetStackLink(StackLink *head,ElemType *e){
    if(StackLinkEmpty(*head))
        return ERROR;
    StackLink p;
    p=(*head)->next;
    *e=p->data;
    return OK;
}
Status destroyStackLink(StackLink *L){
    StackLink p,q;
    p=*L;
    while(p){
        q=p;
        p=p->next;
        pfree(q);
    }
}
void StackLink_Test(){
    StackLink sl;
    int e;
    InitStackLink(&sl);
    PushStackLink(&sl,8192);
    PushStackLink(&sl,8191);
    PushStackLink(&sl,8190);
    PopStackLink(&sl,&e);
}